var app = getApp();
const cnConvert = require('../../utils/changefont.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
      offset:0,
      loading:true,
      dataList:[],
      stime:'',
      etime:'',
      userid:0,
      usertype:0,
      pageText:{
        'title':'我的咖缘吧',
        'jqbh':'机器编号',
        'jqmc':'机器名称',
        'jqwz':'机器位置',
        'hzsj':'合作时间',
        'mysj':'没有数据'

      }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {





    if (options.userid){
        this.setData({
          userid: options.userid,
          usertype: options.usertype
        })
    }
    if (wx.getStorageSync('userDo').font == 1) { //切换繁体
      var textObj = this.data.pageText
      for (var item in textObj) {
        textObj[item] = cnConvert.traditionalized(textObj[item])
      }
      this.setData({
        pageText: textObj
      })
      wx.setNavigationBarTitle({ title: this.data.pageText.title })
    }

    this.getDataList();
    var user = wx.getStorageSync('userDo')
    this.setData({
        stime: user.startTime.substring(0,10),
        etime: user.endTime.substring(0, 10)
    })
  },
  detail:function(e){
      var item = JSON.stringify(e.currentTarget.dataset.item)     
      wx.navigateTo({
          url: '/pages/coffeeMenu/coffeeMenu?item='+item,
      })
  },
  lower: function () {
      var page = this.data.offset
      page++
      this.setData({
          offset: page
      })
      this.getDataList();
  },
  getDataList:function(){
      var that = this;
      var id = 0;
      var usertype = 0;
      that.setData({
          loading: true
      })
      var user = wx.getStorageSync('userDo')
      if (this.data.userid){
        id = this.data.userid;
        usertype = this.data.usertype;
      }else{
        id = user.userId
        usertype = user.type
      }
      wx.request({
          url: app.globalData.api + 'getMakerListByUserId',
          data:{
              type: usertype,
              userId: id,
              offset: that.data.offset
          },
          success:function(res){
              that.setData({
                  loading: false
              })
              if (res.statusCode == 200) {
                  var list = that.data.dataList
                  for (var i = 0; i < res.data.length; i++) {
                      list.push(res.data[i])
                  }
                  that.setData({
                      dataList: list
                  })
              }
          }
      })
  }


})